# -*- coding: utf-8 -*-
from odoo import models, fields, api

class ExpenseSourceLimit(models.Model):
    _inherit = "hr.expense.sheet"

    name = fields.Char(string='報銷單總匯', default=lambda self: self.env['ir.sequence'].next_by_code('hr.expense.sheet.name'), required=True)

class HRExpenseSourceLimit(models.Model):
    _inherit = "hr.expense"

    quantity = fields.Float(required=False)
    product_uom_id = fields.Many2one('product.uom', required=False)
    date = fields.Date(required=True)
    employee_id = fields.Many2one('hr.employee', required=False)

    # 取得新新編號後，加回去原本名稱。
    @api.multi
    def submit_expenses(self):
        res = super(HRExpenseSourceLimit, self).submit_expenses()
        tmp = res['context']['default_name']
        tmp = self.env['ir.sequence'].next_by_code('hr.expense.sheet.name') + tmp
        res['context']['default_name'] = tmp
        return res